import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
import ElementUI from 'element-ui'
import moment from 'moment'                     // api: https://github.com/ElemeFE/element
import '@/icons'                              // api: http://www.iconfont.cn/
import 'element-ui/lib/theme-chalk/index.css'
import '@/assets/scss/index.scss'
import httpRequest from '@/utils/httpRequest' // api: https://github.com/axios/axios
import { isAuth } from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import jsoneditor from 'jsoneditor'
import Print from 'vue-print-nb'
import VueDraggableResizable from 'vue-draggable-resizable'
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'

Vue.component('vue-draggable-resizable', VueDraggableResizable)
Vue.use(Print)
Vue.prototype.$jsoneditor = jsoneditor
Vue.use(VueCookie)
Vue.use(ElementUI, { size: 'mini' })
Vue.config.productionTip = false
Vue.prototype.moment = moment
Vue.prototype.validSe = function (value, number = 255) {
  value = value.replace(/[`～*~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘’，。、]/g, '').replace(/\s/g, '')
  if (value.length >= number) {
    this.$message({
      type: 'warning',
      message: `输入内容不能超过${number}个字符`
    })
  }
  return value
}
// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.isAuth = isAuth     // 权限方法

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  data() {
    return {
      clientHeight: {
        height: '100%'
      }
    }
  },
  router,
  store,
  template: '<App :style="clientHeight"/>',
  components: { App },
  mounted() {
    this.resize()
    window.addEventListener('resize', () => this.resize())
  },
  methods: {
    resize() {
      this.clientHeight.height = `${document.documentElement.clientHeight}px`
    }
  },
  destroyed() {
    window.removeEventListener('resize', this.resize())
  }
})
